package xiu_xiu.model_public_picture_select;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import java.util.ArrayList;

import me.nereo.multi_image_selector.MultiImageSelectorActivity;


/**
 * 图片选择-业务类
 * Created by yang on 2016/4/28.
 */
public class PictureSelect {
    /**
     * 开启照片选择Activity
     *
     * @param code        intent 回调数字
     * @param maxNum      最大张数
     * @param defaultFile 是单张传一个路径，多张传一个集合
     */
    public static void startPhotoSelect(Context context, int code, int maxNum, Object defaultFile) {
        if (!(context instanceof Activity)) {
            return;
        }

        Intent intent = new Intent(context, MultiImageSelectorActivity.class);
        // 是否显示拍摄图片
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, true);
        // 最大可选择图片数量
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT, maxNum);

        if (maxNum > 0 && maxNum == 1) {
            // 选择模式-单选
            intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, MultiImageSelectorActivity.MODE_SINGLE);
        } else {
            // 选择模式-多选
            intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, MultiImageSelectorActivity.MODE_MULTI);
        }

        // 单选
        if (defaultFile instanceof String) {
            String p = (String) defaultFile;
            if (!TextUtils.isEmpty(p)) {
                ArrayList<String> list = new ArrayList<>();
                list.add(p);
                intent.putExtra(MultiImageSelectorActivity.EXTRA_DEFAULT_SELECTED_LIST, list);
            }

            //多选
        } else if (defaultFile instanceof ArrayList) {
            ArrayList<String> strings = (ArrayList<String>) defaultFile;
            intent.putExtra(MultiImageSelectorActivity.EXTRA_DEFAULT_SELECTED_LIST, strings);

        }


        ((Activity) context).startActivityForResult(intent, code);
    }

}
